<template>
  <section class="h100 account-panel b50">
    <van-row class="a-header">
      <van-row class="a-user">
        <van-row class="icon">
          <img src="../../assets/images/temp/avator.png"/>
        </van-row>
        <van-row class="content">
          账号：{{ userData['account'] }}
          <p>手机号码：{{ userData['phoneTips'] }}</p>
        </van-row>
        <van-row class="know">
          <!--          <img src="../../assets/images/icon/know.png"/>-->
        </van-row>
      </van-row>

      <van-row class="a-bg">
        <van-row class="a-tips">
          <van-row class="left">区服：{{ userData['cpServerName'] }}</van-row>
          <van-row class="right">角色：{{ userData['cpRoleName'] }}</van-row>
        </van-row>
      </van-row>

    </van-row>
    <van-row class="a-tabs">
      <van-row class="item">
        {{ userData['welfareCoin'] }}
        <p>福利币</p>
      </van-row>
      <van-row class="item" @click="onPlatformCoinPay()">
        {{ Math.round(userData['platformCoin'] * 100)  }}
        <p>平台币</p>
      </van-row>
      <van-row class="item">
        {{ userData['moneyYuan'] }}
        <p>余额</p>
      </van-row>
      <van-row class="item">
        {{ userData['couponNum'] }}
        <p>优惠券</p>
      </van-row>
    </van-row>

    <van-row class="a-list">
      <!--      <div class="item" @click="changeAccount()">消费记录</div>-->
      <div class="item" @click="onUpdatePass()">修改密码</div>
      <div class="item" @click="onIdentify()">实名认证</div>
      <div class="item" @click="onPhoneBind()">手机绑定</div>
      <!--            <div class="item no-arrow">-->
      <!--              悬浮球开启-->
      <!--              <van-row class="options">-->
      <!--                <van-switch active-color="#FF9305" v-model="checked" size="24px"/>-->
      <!--              </van-row>-->
      <!--            </div>-->
    </van-row>

    <van-row class="a-list">
      <!--      <div class="item" @click="changeAccount()">管理小号</div>-->
      <div class="item" @click="changeAccount()">切换账号</div>
      <!--      <div class="item" @click="changeAccount()">注销账号</div>-->
    </van-row>
    <van-row class="version-tips">
      <el-sl-panel @click="toXieYiDetail(1,'用户服务协议')">《用户服务协议》</el-sl-panel>
      <el-sl-panel @click="toXieYiDetail(2,'游戏隐私协议')">《游戏隐私协议》</el-sl-panel>
      <el-sl-panel>{{ userData['brPlatformKey'] }}.V{{ sdkVersionCode }}</el-sl-panel>
    </van-row>
    <!--    <van-row class="version-tips">SDK版本：{{ userData['brPlatformKey'] }}.V{{ sdkVersionCode }}</van-row>-->
  </section>
</template>

<script>
import {BRStorage} from "../../utils/brStorage";
import {BRNative} from "../../utils/brNative";

export default {
  data() {
    return {
      checked: true,
      gameId: 0,
      userData: {},
      sdkVersionCode: "",
    }
  },

  created() {
    if(this.$route.query.isShow === '0'){
      this.$router.push("/pay/platformCoin?isShow=0");
    }
    this.getLoad();
  },
  methods: {
    getLoad() {
      let queryData = this.$route.query;
      let userToken = queryData.userToken;
      let loginName = queryData.loginName;
      let fromNative = queryData.native;
      let gameId = queryData.gameId;
      this.gameId = gameId;
      let channelCode = queryData.channelCode;
      let runRomSystem = queryData.runRomSystem;
      let cpServerId = queryData.cpServerId;
      let cpRoleId = queryData.cpRoleId;
      this.sdkVersionCode = this.$route.query.sdkVersionCode;
      if (this.BRIsSetString(fromNative)) {
        BRStorage.setStorage(BRStorage.KeyUserToken(), userToken);
        BRStorage.setStorage(BRStorage.KeyBRLoginName(), loginName);
        BRStorage.setStorage(BRStorage.KeyGameID(), gameId);
        BRStorage.setStorage(BRStorage.KeyChannelCode(), channelCode);
        BRStorage.setStorage(BRStorage.KeyRunRomSystem(), runRomSystem);
        BRStorage.setStorage(BRStorage.KeyBRSDKVersionCode(), this.sdkVersionCode);
        BRStorage.setStorage(BRStorage.KeyBRGameServerId(), cpServerId);
        BRStorage.setStorage(BRStorage.KeyBRGameRoleId(), cpRoleId);
      } else {
        this.sdkVersionCode = BRStorage.getStorage(BRStorage.KeyBRSDKVersionCode());
      }
      let params = {
        userToken: userToken,
        cpServerId: BRStorage.getStorage(BRStorage.KeyBRGameServerId()),
        cpRoleId: BRStorage.getStorage(BRStorage.KeyBRGameRoleId()),
      }
      this.$http(window.config.userHomeApi + '/phone_sdk/home', params).then((res) => {
        let code = res.code;
        if (code !== 1) {
          this.BRToast(res.msg);
        } else {
          this.userData = res.data;
          BRStorage.setStorage(BRStorage.KeyBRPlatformCoin(), this.userData['platformCoin']);
        }
      });
    },


    //修改密码
    onUpdatePass() {
      if (this.userData['phoneBind'] !== 1) {
        this.BRDialog("未绑定手机，不能修改密码");
      } else {
        this.$router.push("/account/passwordUpdate");
      }

    },
    //身份绑定
    onIdentify() {
      this.$router.push("/account/identifyBinding");
    },
    //手机绑定
    onPhoneBind() {
      if (this.userData['phoneBind'] !== 1) {
        this.$router.push("/account/phoneBinding");
      } else {
        this.$router.push("/account/phoneUpdate");
      }
    },
    //切换账号
    changeAccount() {
      BRNative.changeAccount();
    },
    //平台币充值
    onPlatformCoinPay() {
      this.$router.push("/pay/platformCoin");
    },

    //FAQ详情
    toXieYiDetail(type, title) {
      this.$router.push({
        path: "/contract",
        query: {
          gameId: this.gameId,
          type: type,
          title: title,
          showTitle: 1,
        },
      });
    },
  }
};
</script>

<style scoped lang='less'>
@import "../../assets/css/account/index.less";
</style>
